home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-2.iso / Files II / Prog / N-P / OOP for C.sit / OIC.ƒ / Explorers Kit Documentation < prev    next >
Encoding:
Text File  |  1988-12-09  |  35.1 KB  |  849 lines  |  [TEXT/KAHL]

  1.                            O.I.C  Objects-in-C
  2.                            ===================
  3.                        
  4.                        Explorer's Kit Documentation
  5.                     
  6.                     Copyright © John Wainwright, 1988
  7.                     
  8.                          454 West 20th Street, #2
  9.                          New York, NY  10011
  10.                          
  11.                          Compuserve : 72657,2534
  12.                          
  13.                           All rights reserved
  14.                        
  15.                           Shareware fee : $20
  16.                        
  17.          This is the shareware, explorer's release of a portable
  18.          object-oriented programming environment for the C pro-
  19.          gramming language.  The kit contains the complete objects
  20.          environment, a bunch of simple, but useful demo classes
  21.          and this, EXPERTS ONLY, documentation - enough for ex-
  22.          perienced C programmers that know something about object-
  23.          oriented techniques to take advantage of them in the
  24.          excellent C environments now on the Mac.
  25.          
  26.          It is supplied as a verion 3, LightSpeed C project but
  27.          the source files are simple text files that should be
  28.          readable by any of the Macintosh C compilers.
  29.          
  30.          The full release will come with complete documentation 
  31.          and an EXTENSIVE set of classes for developing Mac
  32.          applications - a persistent object store, a complete
  33.          Model-View-Controller system for accessing the Mac
  34.          toolbox, 2D & 3D PHIGGS-like imaging spaces integrated
  35.          with the MVC system, a polymorhpic, object-oriented
  36.          spreadsheet system, and an embeddable Common Lisp
  37.          subset interpreter with OIC interface.
  38.          
  39.          Acknowledgements:  Tim Long and Andrew Nicholson
  40.                              both contributed materially to
  41.                              the ideas in this system.
  42.          
  43. Introduction
  44.  
  45.    OIC is a state-of-the-art object-oriented programming environment for
  46.    the C programming language implemented as a portable library of 
  47.    management routines and a set of programming conventions.  It
  48.    features the following :
  49.    
  50.          •      A fully dynamic class structure
  51.          •      Multiple inheritence
  52.          •      Class variables & class methods
  53.          •      Generic function method dispatch with method caching
  54.          •    True run-time polymorphism
  55.          •      Support for multi-methods
  56.          •      No need for a special pre-processor - will work with ANY C
  57.          •      High speed access to instance variables via C structures
  58.          •      Method dispatch tracing system
  59.          •      Smooth & arbitrary transition between C & OOP code
  60.          
  61.        OIC has more of the flavor of the dynamic, Lisp-based OOPS &
  62.        SmallTalk than of the static languages like C++ and Object Pascal.
  63.        Some of the features, like generic functions, are reasonably
  64.        avant-garde, and are described in the following sections.
  65.        
  66.        There is one major departure from the semantics of these OOP systems
  67.        as a consequence of using no pre-processor & deciding to access
  68.        instance variables via C structures: instance variables effectively 
  69.        have a SINGLE level of scoping.  See the section on Limitations, below
  70.        for a full discussion.
  71.        
  72.        This document assumes a detailed familiarity with C and a reasonable
  73.        understanding of object-oriented programming techniques.  For those 
  74.        without the latter, try "Object-Oriented Programming for the 
  75.        Macintosh" by Kurt Schmucker or "Object-Oriented Programming in
  76.        Common Lisp" by Sonya Keene. The following sections describe the
  77.        implementation approach & memory structures, OIC limitations and
  78.        the example file set.  At the end is a reference list of library
  79.        functions & macros, some warnings about portability limitations,
  80.        and details of the shareware licence. 
  81.                 
  82.                             ------------------
  83.  
  84. Implementation 
  85.  
  86.     This section describes the 3 prime elements of the OIC
  87.     system :
  88.     
  89.         •    object layout, management and access
  90.         •    class layout, management and access
  91.         •    generic function & method creation and dispatch
  92.         
  93.     All 3 involve structures created & managed at run-time by the OIC
  94.     library.  In this version, ALL the structures are allocated as 
  95.     handles, locked & then dereferenced.  This is NOT good form, but
  96.     seems to be the quickest memory management scheme on the Mac.  If
  97.     it offends you, the storage allocation routines in "memory.c" can
  98.     be changed to suit.  The decision to use pointers & not handles
  99.     was to promote portability to C environments other than on the
  100.     Macintosh; a future version may use handles.
  101.     
  102.     Objects
  103.     
  104.         Objects are layed-out in memory as a class tag followed by
  105.         the concatenation of all the instance variables (IVs) defined
  106.         in the object's component classes - i.e., its class and all
  107.         its superclasses, and all their super classes, etc.  Each
  108.         object is allocated as a single block of memory and the IVs 
  109.         are zero-filled.  The class tag defines the object's class
  110.         and is actually a pointer to the class's defining structure
  111.         (described below).  The IV's defined by each component class
  112.         are mapped & accessed by ordinary C structures - when a method
  113.         is invoked, a pointer is supplied that points to the local
  114.         IV structure, i.e., the IVs defined in the class in which the
  115.         invoked method was found.
  116.         
  117.         Objects are always referred to by pointers.  The provided
  118.         "object" typedef declares a pointer storage type that will
  119.         hold a pointer to ANY class of object - the system is
  120.         dynamically polymorhpic.  IVs can be any C type including,
  121.         of course, object.
  122.         
  123.         Objects are created with the "New" function.  It takes a
  124.         class & any number of following arguments.  When created,
  125.         the object has its "new" generic function invoked which
  126.         is passed the other, presumably initialisation, arguments.
  127.         
  128.         It is the programmers responsibilty to explicitly free
  129.         memory occupied by unused objects.  The generic function
  130.         "dispose", a method for which is provided in default by
  131.         the root class "Object", will free the originally
  132.         allocated object.  This should be specialised
  133.         if any other housekeeping is needed.  By convention, 
  134.         the generic "deepDispose" will free the object and, 
  135.         recursively, any contained objects.  This, for example,
  136.         is how the supplied List class lists are freed in one go.
  137.                 
  138.                             ------------------
  139.  
  140.     Classes
  141.     
  142.         OIC provides full multiple inheritence of methods.  This is
  143.         supported by a run-time collection of "Class" objects (yes,
  144.         classes are proper objects) arranged in directed, acyclic
  145.         graph.  This D.A.G. maps the inheritence relationships
  146.         among the classes.  All classes inherit eventually from
  147.         the root class "Object" which provides a bunch of useful
  148.         default methods. (see "object.c" for its definition).
  149.         
  150.         Each object is tagged by a pointer to its class's object.
  151.         This is how OIC determines an object's class and contrives
  152.         to dispatch the correct method for a given generic function
  153.         invokation.  Each class object contains instance allocation 
  154.         and IV mapping information, an immediate superclass list,
  155.         the class variables and method invokation information.
  156.         Clearly, a class must exist before any instances of it
  157.         can be created.
  158.         
  159.         The general intention is that each class be defined in a 
  160.         separate source file (see examples) to promote information
  161.         hiding, functional independance & all those good things.
  162.         Each file contains the IV & CV structure definitions, a global 
  163.         to hold the class object, the methods which are written as
  164.         static functions, and an initializing function that creates
  165.         the class and associates its methods with their generic
  166.         functions (see below).
  167.         
  168.         A class is created by the "NewClass" function.  It takes as
  169.         arguments, the size of the IV & CV structures, a class name
  170.         (as a C string) and a null-terminated list of superclasses. 
  171.         The order of this list determines the inheritence priority.
  172.         The supplied method finder does a breadth-first search up
  173.         the superclass tree, scanning across the superclass lists
  174.         at each level in the order in which they were specified to
  175.         the NewClass function. Clearly also, "super"classes
  176.         must exist before they can be specialized or mixed-in.
  177.         
  178.         OIC supports class variables and class methods - see the 
  179.         "IndexMixin" class for an example of how they work.
  180.                 
  181.                             ------------------
  182.  
  183.     Generic Functions and Methods
  184.     
  185.         OIC uses the Generic Function (GF) technique of method dispatch,
  186.         prefered in the current state-of-the-art LISP object-oriented
  187.         systems like CLOS, New Flavors, Common Loops, and Object LISP.
  188.         It has several semantic & performance advantages over the
  189.         message passing schemes and embeds exceptionally cleanly in
  190.         functional languages (like C).
  191.         
  192.         Instead of sending a message identifier to an object as in 
  193.         SmallTalk, or qualifying a function name by a class name as in
  194.         Object Pascal, the generic function is a single function
  195.         defined over a number of argument classes.  It acts like
  196.         a dispatcher which invokes the appropriate method (or methods)
  197.         depending on the class of one (or more) of its arguments and
  198.         hence is "generic".  In the terminology a "generic function"
  199.         embodies many operations depending on the class of its
  200.         arguments.  The different operations are defined by "method
  201.         functions", one in each of the classes that will directly
  202.         handle that generic.
  203.         
  204.         For example, in a messaging-passing system we might have :
  205.         
  206.                     send("append", list, item);
  207.                     
  208.         In a GF system this becomes :
  209.         
  210.                     append(list, item);
  211.                     
  212.         "append" being a function which dispatches to one of the
  213.         various appending methods depending on the class of its first
  214.         argument. This is clearly the preferred form for embedding
  215.         in C. Apart from looking good, a number of neat things follow
  216.         from this technique.
  217.         
  218.         Firstly, it is very simple to write high-speed, caching 
  219.         method dispatchers, usually requiring only a single indexing
  220.         operation to get the method required.
  221.         
  222.         Secondly, individual generic functions can be made to have
  223.         their own dispatching semantics by allowing programmers to
  224.         straight-forwardly define their own dispatching functions.
  225.         
  226.         For example, generic functions can be cleanly made to be driven
  227.         by the classes of several arguments, not just one, allowing
  228.         the implementation of so-called multi-methods.  In a
  229.         mixed-mode arithmetic system, we might have something like :
  230.         
  231.                     add(a, b);
  232.                     
  233.         where a & b have different classes & hence some coercion is
  234.         required.  A dispatching function for a set of math generic
  235.         functions might look at the classes of the arguments, decide
  236.         on the mutually widest class, invoke coercion generics on 
  237.         a & b to that wider class & invoke the add generic on the
  238.         coercions :
  239.         
  240.                     add(coerce(a, wide), coerce(b, wide));
  241.                     
  242.         Another example might be a dispatching function that will handle
  243.         before, after & around methods in the way of ZetaLisp's Flavors.
  244.         
  245.     Defining Generic Functions
  246.     
  247.         OIC comes supplied with only a single kind of generic function;
  248.         one that dispatches on the class of the first argument -
  249.         equivalent to simple message-passing. If inheritence is
  250.         needed it follows a BREADTH-FIRST search up the superclass tree
  251.         caching any found methods for subsequent single-index dispatch.
  252.         
  253.         Generic functions of this simple type are defined using the
  254.         "defGeneric" macro (defined in "object.h").  This macro is
  255.         unfortunately very unwieldly - it requires 3 arguments which
  256.         are just variants of the generic's name (if ONLY one could
  257.         construct symbols & strings in the standard C preprocessor!!!)
  258.         It declares a function with the generic's name having the
  259.         above-mentioned dispatching semantics and declares some tables
  260.         that hold pointers to the method functions.  This method 
  261.         table is used by the dispatching code and is in two parts,
  262.         one for normal methods & the other for class methods; they
  263.         are both indexed by a unique "class index" which is allocated
  264.         when the class is created.
  265.         
  266.         Other kinds of dispatching semantics would be implemented by
  267.         defining and using variants of the defGeneric macro. The
  268.         technique allows multiple concurrent defGeneric variants.
  269.         
  270.     Defining & Invoking Method Functions
  271.     
  272.         As mentioned in the Class section above, the various methods
  273.         for a class are usually defined as static functions in that
  274.         class's source file.  Method functions are passed 3
  275.         arguments on invokation: the dispatching object, a pointer
  276.         to the local IV structure in that object, and a pointer
  277.         to the rest of the arguments given to the generic. For
  278.         example, the generic invokation :
  279.         
  280.                 set(window1, "Untitled", &rect1, VISIBLE);
  281.                 
  282.         would result in calling a method function declared :
  283.         
  284.                 static object
  285.                 set_method(self, ivs, args)
  286.                     object        self;
  287.                     window_iv    *ivs;
  288.                     struct 
  289.                     {
  290.                         char    *title;
  291.                         Rect    *frame;
  292.                         int        visFlag;
  293.                     } *args;
  294.                 {
  295.                     .....
  296.                     ivs->title = args->title;
  297.                     .....
  298.                     set_frame(self, args->frame);
  299.                     .....
  300.                     return self;
  301.                 }
  302.                 
  303.         such that "self" points to the key object "window1",
  304.         "ivs" points to the "window_iv" structure within that
  305.         object (remember all the IV structures of the component
  306.         classes are concatenated to form an object), and "args"
  307.         points to the string & the rectangle arguments.
  308.         
  309.         The "args" argument actually points into the call frame
  310.         of the generic function "set" at its secondary arguments
  311.         on the stack.  This is done for speed & so the dispatcher 
  312.         doesn't have to know how many arguments there are.  This is
  313.         guarranteed to work only in C implementations that use
  314.         the stack for passing arguments (all the C's on the Mac).
  315.         Some C's on large machines with millions of registers use
  316.         them instead of the stack for argument passing and OIC's
  317.         technique wont work (see portability limitations, below).
  318.         
  319.         Also, on those C's that use the stack, structures are
  320.         layed-out in the same way as arguments on the stack,
  321.         so the in-line argument structure declaration is a neat
  322.         way of getting at these "passed-on" arguments.  Remember,
  323.         though, that chars are widened to ints and floats to doubles
  324.         when being placed on the argument stack - they must be
  325.         declared as this widened form in the argument mapping 
  326.         struct.
  327.         
  328.         Note in the example, above, how the IVs & arguments are
  329.         accessed in clean, high-speed ways.
  330.         
  331.     Associating Methods with Generic Functions
  332.     
  333.         A generic function is implemented by a bunch of method
  334.         functions, one from each of the classes that is so 
  335.         inclined.  The association of a method with its generic
  336.         is usually done in the class source file, in the initializing
  337.         function that creates the class (see the example classes).
  338.         
  339.         The function "AddMethod" performs this task and is tuned
  340.         to take a bunch of methods defined in one class & associate them
  341.         one-by-one with each's particular generic.  It takes a class object
  342.         as its first argument followed by a null terminated list of
  343.         pairs: the generic's method table (declared by "defGeneric") and
  344.         the method function, e.g.
  345.         
  346.             AddMethods(List, appendGeneric, appendMethod,
  347.                              headGeneric,   headMethod,
  348.                              tailGeneric,   tailMethod,
  349.                              ....,
  350.                              NULL);
  351.                             
  352.         AddMethods can be called any time and any number of times after
  353.         a class has been created to incrementally add its methods. An
  354.         equivalently argumented function called "AddClassMethods" will
  355.         add class methods to the generics specified. (see IndexMixin.c
  356.         for an example).
  357.                 
  358.                             ------------------
  359.  
  360.     Limitations
  361.     
  362.            Embedding such a system in standard C necessarily involes trade-
  363.            offs.  Some of these have resulted in limitations and others
  364.            in the need for rather cryptic code.
  365.            
  366.            Scope and Inheritence of Instance Variables
  367.            
  368.             The decision to map object instance variables by C 
  369.                structures results in the only major departure from
  370.                conventional OOPS semantics - the SCOPE of instance 
  371.                variables is effectively limited to the level in the class
  372.                hierarchy that defines them.  This single level of
  373.                scoping immediately implies that ALL instance & class 
  374.                variables are inherited; there is no "hiding" of similarly-
  375.                named instance variables up the inheritance chain
  376.                as occurs in some other OOP systems.
  377.             
  378.             Some would contend that this is due & proper adherence
  379.             to the programming principles of encapsulation and,
  380.             fortunately, it rarely causes problems - one tends to be
  381.             interested in the goings-on of the IVs in the 
  382.             methods of the class that defined the IVs. However,
  383.             on some occasions, especially when slightly specialising
  384.             an existing class, it is handy to be able to get at the 
  385.             IVs for that class, and there are 2 ways to achieve this.
  386.             
  387.             The first is to use one of the macros "localIVs" or "myIVs".
  388.             The first allows you to reach into any object of the same
  389.             class as "self" and get IV structure for the current
  390.             method's class.  "myIVs" reaches into "self" and gets the
  391.             IVs for any one of its superclasses. See Macros, below for
  392.             further details.
  393.             
  394.             The second way is to use methods to access IVs.  Indeed, most
  395.             of the Lisp OOPS do it this always; the OOPS system 
  396.             automatically generating the accessing methods - very easy
  397.             to do in Lisp, not so in C.  This technique can, of course,
  398.             be used on an IV-by-IV basis; provide access methods for
  399.             only those that will need to be accessed by specializing
  400.             classes.  Because inherited methods have a nested scoping - 
  401.             closer ones hide ones farther up the inheritence chain - this
  402.             technique also provides a way of implementing nested 
  403.             inheritence of selected IVs.
  404.             
  405.                                 ------------------
  406.  
  407.        Source File Structure & Coding Conventions
  408.        
  409.            In the example classes and according to the recommended way of
  410.            using OIC there is one source file for each class.  This
  411.            yields a convenient modularity and allows the desired
  412.            kinds of information hiding to be set up.  Each class
  413.            source file usually contains :
  414.            
  415.                1.    The IV & (possibly) CV structure definitions.
  416.                     They will need to be moved out into an include
  417.                     file if several classes (which should always
  418.                    be inheriting classes) are to get at them.
  419.                    
  420.                2.    A class global to hold the class object.
  421.                
  422.                3.    The methods defined in this class, usually
  423.                    as static functions.  Note in the example
  424.                    classes that these are named with the 
  425.                    generic name prefixed by an underscore - you
  426.                    might be happier with the generic name post-
  427.                    fixed with "Method"; in any event, they must 
  428.                    be different from the actual generic function's
  429.                    name.
  430.                    
  431.                4.    Any local utility function that the above might use.  
  432.            
  433.                5.    An initializing function that creates the class
  434.                    and associates its methods with their corresponding
  435.                    generics.  This function needs to be called during
  436.                     initialization in the main code.
  437.            
  438.            The declaring of generic functions requires some care.  They
  439.            are intended to be program-wide globals and are probably best
  440.            all declared in one spot because almost any class might 
  441.            wind up defining a method for one.  In the example file set
  442.            they are all declared in "generics.c".  They also need to be
  443.            declared external in all the source files that might use
  444.            them; in the example kit this is done in the include file
  445.            "generics.h".
  446.            
  447.            Any file that uses OIC should include "oic.h" - it defines
  448.            all the OIC typedefs, macros & externals.
  449.                 
  450.                             ------------------
  451.  
  452.     Example File Set
  453.     
  454.         This explorer's kit is intended primarily to place a working
  455.         object-oriented C programming mechanism into the hands of 
  456.         expert C programmers for their edification, enjoyment and,
  457.         hopefully, serious use.  The demo classes and small test
  458.         main program are not intended to be a tutorial on OOPS
  459.         programming, nor to necessarily form the basis for a serious
  460.         suite of classes.  They are simply the test classes I built
  461.         as OIC came together, suffer somewhat from its growing
  462.         pains, and are provided to help illuminate the basic
  463.         object manager.
  464.         
  465.         The base object manager is represented in the files :
  466.         
  467.             oic.c          - the basic management routines
  468.             memory.c    - customizable object allocation routines
  469.             oic.h           - the include file for anybody using oic
  470.             object.c    - the root class
  471.             class.c        - the class class
  472.             
  473.         Certain of the class files go to make up whats called the
  474.         system classes :
  475.         
  476.             list.c         - a general purpose list class
  477.             string.c     - a class to hold C strings
  478.             replist.c     - a representation class for nested objects
  479.             collect.c     - a generic superclass that adds lots of
  480.                            neat collection methods to any class that
  481.                            provides head, tail, push & eq
  482.             list2.c         - a version of the list class using Collect
  483.             indexMixin.c - a mixin (a modifying superclass) that will
  484.                            keep track of all the instances of a class
  485.                            that uses it as a superclass
  486.             linkseq.c     - a general purpose sequencing class for
  487.                            classes that understand head, tail & isEmpty
  488.             generics.c   - defGenerics for all the above classes
  489.             generics.h     - external definitions for the above classes
  490.         
  491.         Notes:
  492.         
  493.         1. The List class does NOT implement standard LISP lists, the
  494.            operations all destructively modify the subject list. It
  495.            will only hold OIC objects as elements.
  496.         2. The IndexMixin class provides an example of how to use
  497.            class variables & class methods.  It specializes the "new"
  498.            method & maintains a list (using the List class) of each
  499.            instance of a class inheriting from it in a class variable.
  500.            They can be got by invoking "allInstances" on the class you
  501.            are keeping track of. It also adds a "sequence" class method
  502.            so you can simply sequence over the class.
  503.         3. The Replist class is a specialization of the List class
  504.            intended to help formatting & printing nested objects
  505.            like Lists.  It gets used by the repList methods in various
  506.            classes to create a structure isomorphic to the object
  507.            being printed but with String representations of the
  508.            object's leaf values instead of the values themselves.
  509.            This can then be neatly parenthesised & indented, etc. See
  510.            how it gets used by looking at the print method in the
  511.            root Object class (object.c).  This print method is
  512.            inherited by EVERY class and so provides a simple
  513.            object printer for any class that can generate a Replist
  514.            of itself (see List).
  515.         4. the Linkseq class is an example of what could be
  516.            a suite of sequencing utility classes.  Its purpose is
  517.            to wrap up an object that is being sequenced over to
  518.            provide the sequencing context.  Note how it gets used
  519.            in the test program, main.c.  There are several
  520.            "for" statements that invoke the "sequence" generic on
  521.            an object.  Any object that is sequencable should 
  522.            define a sequence method that will wrap itself up
  523.            in, and return, one of these utility sequence classes.
  524.            This class should, in turn, respond to the generics
  525.            "start", "next", "moreInSeq", & "restart".  Other
  526.            kinds of sequence "wrapper" classes might work for
  527.            scalars by generating consecutive values, strings by
  528.            sequencing through the characters, or arrays by indexing
  529.            through their elements.  See how neatly (in main.c) we get
  530.            general purpose polymorphic sequencing in an ordinary
  531.            old C "for" statement. 
  532.         
  533.         A small test program with some other little classes is 
  534.         contained in the files :
  535.         
  536.             main.c        - the main test procedure
  537.             coord.c        - a kind of point class
  538.             box.c        - a kind of rectangle class
  539.             window.c    - a trivial window class that experiments
  540.                           with keyword arguments!
  541.                 
  542.                             ------------------
  543.  
  544.        OIC System Typedefs
  545.        
  546.         typedef struct class *class            - declares a holder for a class object
  547.         typedef struct class **object        - declares a holder for an object
  548.         
  549.        OIC System Functions
  550.        
  551.         class  NewClass(iv_size, cv_size, name, super1, super2, ... NULL)
  552.                     int     iv_size;
  553.                     int     cv_size;
  554.                     char     *name;
  555.                     class    super1, super2, ...;
  556.                     
  557.                     creates a new class with local IV & CV structure sizes as given
  558.                     and that inherits from the null-terminated list of superclasses.
  559.                     The order of this list determines the inheritence priority.
  560.                     The supplied method finder does a breadth-first search up
  561.                     the superclass tree, scanning across the superclass lists
  562.                     at each level in the order in which they were specified to
  563.                     the NewClass function.
  564.                     The class name is used for debugging & tracing output.
  565.                 
  566.         object New(class, initializing arguments ...)
  567.                     class    class
  568.                     <any>    initializing arguments ...;
  569.                     
  570.                     creates a new object of the given class. Invokes the "new"
  571.                     generic on the fresh object, passing it the initialization
  572.                     arguments.
  573.         
  574.         void   AddMethods(class, generic1, method1, generic2, method2, ..., NULL)
  575.                     class        class;
  576.                     MethodTable    generic1, generic2, ...;
  577.                     <any>        (*method1)(), (*method2)() ...;
  578.                     
  579.                     associates methods for the given class with their generic
  580.                     functions.  The generics are specified by passing the method
  581.                     table that is created by the "defGeneric" macro (see below).
  582.                     
  583.         
  584.         void   AddClassMethods(class, generic1, method1, generic2, method2, ..., NULL)
  585.                     class        class;
  586.                     MethodTable    *generic1, *generic2, ...;
  587.                     <any>        (*method1)(), (*method2)() ...;
  588.                     
  589.                     associates class methods for the given class with their generic
  590.                     functions.  The generics are specified by passing the method
  591.                     table that is created by the "defGeneric" macro (see below).
  592.                     
  593.         object Super(object, arguments...)
  594.                     object    object;
  595.                     <any>    arguments;
  596.                     
  597.                     invokes the method for the currently executing generic that is
  598.                     next higher up the inheritance path than the current method. This
  599.                     is very useful when one wishes merely to augment the operation
  600.                     of an inherited method, rather than completely replace it.
  601.  
  602.         object SuperPassArgs(object, argumentListPtr)
  603.                     object    object;
  604.                     <any>    *argumentListPtr;
  605.                     
  606.                     same as "Super" but a pointer to the argument list is given
  607.                     rather than specifying them in place.  This is useful for passing
  608.                     the argument list pointer that a method normally gets straight
  609.                     through to the super method.
  610.                     
  611.  
  612.         int    SizeOf(object)
  613.                     object    object;
  614.                     
  615.                     returns the total size of the object in bytes.
  616.                     
  617.         char   *ClassNameOf(object)
  618.                     object    object;
  619.                     
  620.                     returns the class name of the object as a C string.
  621.                     
  622.         char   *MethodName(generic)
  623.                     MethodTable    *generic;
  624.         
  625.                     returns the name of a generic as a C string given the generics
  626.                     method table (as defined by "defGeneric", see below).
  627.                     
  628.         int    IsA(object, class)
  629.                     object    object;
  630.                     class    class;
  631.                     
  632.                     returns true if the object is of the given class.
  633.                                         
  634.         int    IsAKindOf(object, class)
  635.                     object    object;
  636.                     class    class;
  637.                     
  638.                     returns true if the object is of the given class or inherits from
  639.                     that class.
  640.                                         
  641.         int       IsObj(object)
  642.                     object    object;
  643.                     
  644.                     attempts to check whether object is a valid object. It does 
  645.                     this by ensuring that "object" is a valid pointer, points into
  646.                     the application heap, points at a tag that points at a class
  647.                     which itself has a tag which must point to the "Class" object.
  648.                     Clearly, it can be fooled, so beware.
  649.                     
  650.         void   InitOIC()
  651.         
  652.                     creates & initializes the OIC system.  Should be called
  653.                     EXACTLY once before any of the OIC functionality is used.
  654.         
  655.         void   InitSysClasses()
  656.         
  657.                     creates & initializes the system classes.
  658.         
  659.         void    TraceOn()                - turns on generic call tracing
  660.         void    TraceOff()                - turns it off
  661.         void    TraceObj(object)        - traces any generics called on object
  662.         void    TraceClass(class)        - traces any generics ony any "class" object
  663.         void    dumpClass(class)        - debugging class dump
  664.         void    dumpMethodTable(mth)    - debugging method table dump
  665.  
  666.     OIC System Globals
  667.  
  668.         class currentClass;        - the class in which the currently executing
  669.                                   method was found.
  670.         class classes;            - a linked list of all classes created. You can 
  671.                                   get a List of the classes by invoking subs(Object);
  672.         class Class;            - the class class.
  673.         class Object;            - the root object class. ALL classes inherit 
  674.                                   eventually from Object
  675.  
  676.     Object methods
  677.     
  678.         The following methods are provided as defaults by the root class Object.
  679.         ALL classes, therefore, support these methods by default inheritence.
  680.                                   
  681.         eq(obj1, obj2)            - a byte wise comparison of the contents of each 
  682.         new(obj, args...)        - dummy "new" method
  683.         className(obj)            - class name as a String object
  684.         print(obj)                - invokes print(repList(obj))
  685.         repList(obj)            - default object representation. creates a
  686.                                   replist by stepping through obj
  687.                                   sizeof(object) (4 bytes) at a time. If
  688.                                   the current 4 bytes is a valid object
  689.                                   reference recursively calls repList,
  690.                                   otherwise adds a hex representation to
  691.                                   the repList
  692.         map(obj, f)                - maps the function "f" over each item in "obj"
  693.                                   by using "sequence" on "obj".
  694.         dispose(obj)            - frees the memory occupied by "obj"
  695.         
  696.     Class methods
  697.     
  698.         supers(class)            - returns a (List) list of all the classes ancestors
  699.         subs(class)                - returns a (List) list of all the classes that 
  700.                                   inherit from "class"
  701.         print(class)            - prints the class name
  702.         repList(class)            - returns the class name as replist
  703.  
  704.         
  705.     OIC System Macros & Defines
  706.  
  707.         defGeneric(generic, methodTable, name)
  708.         
  709.                 declares a generic function and its attendant method table.
  710.                 This macro must be called once for each unique generic
  711.                 function in the system - generics are global functions.
  712.                 The macro is given the generic's name, the name to be used
  713.                 for the generic's method table, and the generic's name as
  714.                 a C string constant.
  715.                 
  716.                 If C's preprocessor were even the tiniest bit smart it would
  717.                 allow one to create symbols & strings & you have only had to
  718.                 give defGeneric one argument. Ah, well.
  719.                 
  720.                 For example :
  721.                 
  722.                         defGeneric(print, printGeneric, "print");
  723.                     
  724.         externGeneric(generic, methodTable)
  725.         
  726.                 declares an external reference to a generic function. 
  727.                 Usually both the generic function itself and its
  728.                 method table need to be accessible, and this macro
  729.                 eases their declaration. (see generics.h)
  730.                 
  731.                 For example :
  732.                 
  733.                         externGeneric(print, printGeneric);
  734.  
  735.         localIVs(obj, structure)
  736.         
  737.                 computes a pointer to the IV structure in "obj" for
  738.                 to the current class. This is useful if I'm working
  739.                 with two objects of the same class (say, Lists that
  740.                 I'm concatenating) and I want to reach into the
  741.                 IV's of both of them (see _join in list.c).  The 
  742.                 "structure" argument is just used to cast the 
  743.                 resulting pointer to that which you want (the 
  744.                 structure typedef for the current class's IVs).
  745.                     
  746.         myIVs(class, structure)
  747.         
  748.                 computes a pointer to the IVs of "self" for the
  749.                 given "class".  This is the macro that gets around
  750.                 the one-level scoping problem - I can reach back
  751.                 and get at the IVs of any superclass I want (providing
  752.                 the structure typedefs are available - you may 
  753.                 want to enforce the hiding by keeping these typedefs
  754.                 private).
  755.                     
  756.         localCVs(class, structure)
  757.         
  758.                 as for localIVs but point at the class variables instead.
  759.                     
  760.         myCVs(class, structure)
  761.                     
  762.                 as for myIVs but point at the class variables instead.
  763.         
  764.         ClassOf(object)
  765.         
  766.                 computes the class of the given object
  767.  
  768.         CHECK_OBJS
  769.         
  770.                 if defined in "oic.c" will cause all oic functions to
  771.                 check for valid class & object arguments (by using IsObj()).
  772.                 This is a conditional assembly flag and is set in the
  773.                 distributed kit.
  774.                     
  775.         END
  776.         
  777.                 equivalent to NULL. Used sometimes to mark the end
  778.                 of argument lists.  Another gripe: why didnt they
  779.                 design C so you could find out how many arguments you
  780.                 were given - after all, the function call form is
  781.                 completely polymorphic - I can understand the lack in
  782.                 a language with compile-time isomorphism checks like
  783.                 Pascal.
  784.                 
  785.                             ------------------
  786.  
  787.     Portability Considerations
  788.     
  789.         There is really only one major portability consideration and that 
  790.         involves OIC's expectations about the use of the stack for passing
  791.         arguments.  It expects all arguments to be placed on the stack 
  792.         with earlier arguments at lower addresses. 
  793.         On 680x0s and 80x86s there is no other sensible option and so
  794.         OIC should port without trouble on C compilers for those machines
  795.         (the techniques have been tried on 68010 Unix 4.2BSD and 80286
  796.         Xenix & MS-DOS boxes succesfully).
  797.         
  798.         OIC was developed in THINK's Lightspeed C, an extremely good C
  799.         development environment for the Macintosh. It has also run without
  800.         change using Aztec C.  
  801.         
  802.         The current version does make use of UNIX-like standard I/O calls
  803.         for outputing errors and trace messages. Both LSC and Aztec provide
  804.         a Unix emulation library for this. You may have trouble if your C
  805.         doesn't, in which case you should recode all the printf's &
  806.         fprintf's.  Indeed, in the full OIC, this use of Unix emulation
  807.         will go and be replaced by the use of generic, stream-based text
  808.         window classes.
  809.                 
  810.                             ------------------
  811.  
  812.     Licensing Terms
  813.     
  814.         This software is distributed as shareware; if you wind up using it
  815.         for developing any software, particularly commercial software, please
  816.         send the $20 fee to the address below.  You will become a registered
  817.         user and have access to upgrades & class kits as they become
  818.         available.
  819.         
  820.         The software is also distributed AS IS, with no warranty, expressed or
  821.         implied, of the correctness or suitability of this software for any purpose.
  822.         No responsibility is assumed for damages arising from the use of this 
  823.         software.
  824.         
  825.         OIC is protected by copyright and all commercial rights are reserved.
  826.         Under NO circumstances may this software be distributed in any decodable
  827.         source form, or any form that might be usable as a programming tool
  828.         for commercial advantage.  Reasonable duplication costs can be charged.
  829.         
  830.         Under the shareware ethic, however, you are free to copy & distribute
  831.         the OIC software UNCHANGED, providing this document & licensing terms
  832.         are also copied & distributed with the OIC software.
  833.         
  834.         Feedback & queries are welcome.  I am interested in any classes that
  835.         you may develop - indeed, it seems to me that the success
  836.         of a system like this will primarily be a function of the quantity and
  837.         quality of classes available.
  838.         
  839.             
  840.         Have fun!
  841.             
  842.                         John Wainwright
  843.                         454 West 20th Street, #2
  844.                         New York, NY  10011
  845.                         
  846.                         Compuserve : 72657,2534
  847.         
  848.         
  849.         All OIC files & documentation are Copyright © John Wainwright, 1988